import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            name: 'root',
            redirect: '/layout'
        },
        {
            path: '/layout',
            name: 'layout',
            component: () => import('@/layout/MainLayout.vue'),
            redirect: '/layout/home',
            children: [
                {
                    path: 'home',
                    name: 'home',
                    component: () => import('@/views/home/HomePage.vue'),
                },
                {
                    path: 'social',
                    name: 'social',
                    children: [
                        {
                            path: 'forum',
                            name: "forum",
                            redirect: '/layout/social/forum/forum-home',
                            children: [
                                {
                                  path: 'forum-home',
                                  name: "forum-home",
                                  component: () => import('@/views/social/forum/index.vue')
                                },
                                {
                                    path: "search",
                                    name: "forum-search",
                                    component: () => import('@/views/social/forum/ForumSearch.vue')
                                },
                                {
                                    path: 'post/detail',
                                    name: "post-detail",
                                    component: () => import('@/views/social/forum/PostDetail.vue')
                                },
                                {
                                    path: 'post/person',
                                    name: "post-person",
                                    component: () => import('@/views/social/forum/PostPerson.vue')
                                },
                                {
                                    path: 'bard/detail',
                                    name: "bard-detail",
                                    component: () => import('@/views/social/forum/BardDetail.vue')
                                },
                                {
                                    path: 'bard/list',
                                    name: "bard-list",
                                    component: () => import('@/views/social/forum/BardList.vue')
                                },
                            ]
                        },
                        {
                            path: 'event',
                            name: "event",
                           redirect: '/layout/social/event/home',
                            children: [
                                {
                                    path: 'home',
                                    name: "event-home",
                                    component: () => import('@/views/social/events/index.vue'),
                                },
                                {
                                    path: 'list',
                                    name: "event-list",
                                    component: () => import('@/views/social/events/EventList.vue')
                                },
                                {
                                    path: 'detail',
                                    name: "event-detail",
                                    component: () => import('@/views/social/events/EventDetail.vue')
                                },
                                {
                                    path: 'create',
                                    name: "event-create",
                                    component: () => import('@/views/social/events/EventCreate.vue')
                                },
                                {
                                    path: 'join',
                                    name: "event-join",
                                    component: () => import('@/views/social/events/EventJoin.vue')
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'serve',
                    name: 'serve',
                    children: [
                        {
                            path: 'lost-found',
                            name: "lost-found",
                            redirect: '/layout/serve/lost-found/home',
                            children: [
                                {
                                    path: 'home',
                                    name: "lost-found-home",
                                    component: () => import('@/views/serve/lost-found/index.vue'),
                                },
                                {
                                    path: 'search',
                                    name: "lost-found-search",
                                    component: () => import('@/views/serve/lost-found/LostFoundSearch.vue'),
                                },
                                {
                                    path: 'create',
                                    name: "lost-found-create",
                                    component: () => import('@/views/serve/lost-found/LostFoundCreate.vue'),
                                },
                                {
                                    path: 'edit/:itemId',
                                    name: "lost-found-edit",
                                    /*传递query参数type，类型为lost或者found*/
                                    component: () => import('@/views/serve/lost-found/LostFoundCreate.vue'),
                                },
                                {
                                    path: 'lost/detail/:itemId',
                                    name: "lost-detail",
                                    component: () => import('@/views/serve/lost-found/LostFoundDetail.vue'),
                                },
                                {
                                    path: 'found/detail/:itemId',
                                    name: "found-detail",
                                    component: () => import('@/views/serve/lost-found/LostFoundDetail.vue'),
                                },
                            ]
                        },
                        {
                            path: 're-market',
                            name: 're-market',
                            redirect: '/re-market/sku/list',
                            component: () => import('@/views/serve/re-market/index.vue'),
                            children: [
                                {
                                    path: 'sku/list',
                                    name: "sku-list",
                                    component: () => import('@/views/serve/re-market/SkuList.vue')
                                },
                                {
                                    path: 'sku/detail',
                                    name: "sku-detail",
                                    component: () => import('@/views/serve/re-market/SkuDetail.vue')
                                },
                                {
                                    path: 'sku/create',
                                    name: "sku-create",
                                    component: () => import('@/views/serve/re-market/SkuCreat.vue')
                                },
                            ]
                        }
                    ]
                },
                {
                    path: 'share',
                    name: 'share',
                    redirect: { name: 'share-home' },
                    children: [
                        {
                            path: 'home',
                            name: 'share-home',
                            component: () => import('@/views/share/index.vue')
                        },
                        {
                            path: 'detail/:videoId',
                            name: 'share-detail',
                            component: () => import('@/views/share/ShareVideoDetail.vue')
                        }
                    ]
                },
                {
                    path: 'user/:userId',
                    name: 'user-center',
                    component: () => import('@/views/user/index.vue'),
                    redirect: { name: 'user-info' },
                    children: [
                        {
                            path: 'info',
                            name: 'user-info',
                            component: () => import('@/views/user/UserInfo.vue'),
                            props: true // 启用参数自动转props
                        },
                        {
                            path: 'forum',
                            name: 'user-forum',
                            component: () => import('@/views/user/forum/index.vue'),
                            props: true
                        },
                        {
                          path: 'event',
                          name: 'user-event',
                          component: () => import('@/views/user/event/index.vue'),
                          props: true
                        },
                        {
                            path:"lost-found",
                            name:"user-lost-found",
                            component: () => import('@/views/user/lost-found/index.vue'),
                        },
                        {
                            path:"share",
                            name: "share",
                            component: () => import('@/views/user/share/ShareCenter.vue'),
                            children: [
                                {
                                    path:"info-create",
                                    name: "share-info-create",
                                    component: () => import('@/views/user/share/ShareInfoCreate.vue'),
                                },
                                {
                                    path:"set-create",
                                    name: "share-set-create",
                                    component: () => import('@/views/user/share/VideoSetCreate.vue'),
                                },
                            ]
                        }
                    ]
                },
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/Login.vue'),
        },

        {
            path: '/message/center',
            name: "user-message",
            component: () => import('@/views/message/Message.vue')
        },
    ],
})
//后置守卫，解决页面切换之后滚轮自动回到顶部
router.afterEach((to, from) => {
    window.scrollTo(0, 0) // 立即滚动到顶部
})
export default router
